<?php

namespace app\api\model;

use think\Model;

class Image extends BaseModel
{
    /**
     * 隐藏的字段名称
     * @var array
     */
    protected  $hidden = ['from','name','create_time','delete_time'];
    protected  $autoWriteTimestamp = true;
    protected $updateTime = false;
    public function getUrlAttr($value,$data){
            return $this->prefixImg($value,$data);
    }

    /**
     * 插入图片
     * @param $info
     * @return Image|null
     * @throws \think\exception\DbException
     */
    public static function createImg($info){
        $data = [
            'name'=>$info->fname,
            'url'=>$info->fkey,
            'key'=>$info->fkey,
            'from'=>2
        ];
        $num =  (new Image)->insertGetId($data);
        $result = self::get($num);
        return $result;
    }

    /**
     * 获取图片
     * @param $img_id
     * @return Image|null
     * @throws \think\exception\DbException
     */
    public static function getImg($img_id){
        return self::get($img_id);
    }
    /**
     * 删除图片
     * @param $img_id
     * @return int
     */
    public static function deleteImg($img_id){
        return self::destroy($img_id);
    }



}
